#include "user.h"

User::User(QObject *parent) : QObject(parent)
{

}

User::User(QString id, QString ip, QString password, QString name,
           QString job, QObject *parent) : QObject(parent), online(false)
{
    this->id = id;
    this->ip = ip;
    this->password = password;
    this->name = name;
    this->job = job;
}

void User::UpdInfo(QString ip, QString password, QString name, QString job){
    // id不可变
    this->ip = ip;
    this->password = password;
    this->name = name;
    this->job = job;
}

void User::AddFriend(Friend frd){
    friends.append(frd);
}

void User::DelFriend(Friend frd){
    friends.remove(friends.indexOf(frd, 0));
}

void User::UpdFriend(Friend frd){
    // indexOf检索的是id是否匹配
    friends.replace(friends.indexOf(frd, 0), frd);
}

QVector<Friend> User::getFriends(){
    return friends;
}

void User::AddGroup(Group gp){
    groups.append(gp);
}

void User::DelGroup(Group gp){
    groups.remove(groups.indexOf(gp, 0));
}

void User::UpdGroup(Group gp){
    // indexOf检索的是id是否匹配
    groups.replace(groups.indexOf(gp, 0), gp);
}

QVector<Group> User::getGroups(){
    return groups;
}

void User::Online(){
    online = true;
}
void User::Offline(){
    online = false;
}
